// 云函数入口文件
const cloud = require('wx-server-sdk')
const env = 'bbq-6gz7knah1c296b0f'
cloud.init(env)
const db = cloud.database({ env })


getData = async(tag)=>{
  return await db.collection("articles").aggregate()
  .lookup({
    from:'users',
    localField:'authorId',
    foreignField:'userId',
    as:'articleWithuser'
  })
  .match({tags:tag}).end()
}

// 云函数入口函数
exports.main = async (event) => {
    const active = event.active
    return  getData(active)
}